﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace helicopterFight
{
    class Explosion : GameObject
    {
        private Random rand = new Random();
        private const float extendExpl = 0.1f;
        private const float maxSize = 5f;
        private float removeSize = 7f;
        public bool visible = true;

        //METODY

        public Explosion(Game1 gam)
        {
            model = gam.Content.Load<Model>("models/explosion");
            scale = 1f;
        }

        public void setPos(Vector3 pos)
        {
            position = pos;
        }

        public override void update()
        {
            if (!visible)
                return;

            if (scale <= maxSize)
            {
                scale += extendExpl;
            }
            removeSize -= extendExpl;
            if (removeSize < 0)
                visible = false;
        }

        public override void draw()
        {
            if (visible)
            {
                Matrix[] transforms = new Matrix[model.Bones.Count];
                model.CopyAbsoluteBoneTransformsTo(transforms);

                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (BasicEffect effect in mesh.Effects)
                    {
                        effect.EnableDefaultLighting();
                        effect.PreferPerPixelLighting = true;
                        effect.DiffuseColor = new Vector3(1f, rand.Next(100)/255f, rand.Next(100)/255f);
                        effect.EmissiveColor = new Vector3(1f, 0f, 0f);
                        effect.World =
                            transforms[mesh.ParentBone.Index] *
                            Matrix.CreateFromYawPitchRoll(
                            rotation.Y,
                            rotation.X,
                            rotation.Z) *
                            Matrix.CreateScale(scale) *
                            Matrix.CreateTranslation(position);

                        effect.Projection = cam.CameraProjectionMatrix;
                        effect.View = cam.CameraViewMatrix;
                    }
                    mesh.Draw();
                }
            }
        }
    }
}
